<template>
  <div class="box">
    <!-- 移动端二级菜单 -->
    <div
      class="m_top"
      :class="searchBarFixed== true?'isFixed':''"
      style="border-bottom: 1px solid #e5e5e5;"
    >
      <ul>
        <li v-for="(item,index) in twoList" :key="index" @click="navclick(index)">
          <a>{{item.class_name}}</a>
        </li>
      </ul>
    </div>
    <div class="w1398">
      <!-- PC端菜单 -->
      <div class="left fl P_left" :class="searchBarFixed1== true?'isFixed':''">
        <ul>
          <li @click="navclick_rm(-1)" class="navclick_rm">
            <a>热门推荐</a>
          </li>
          <li v-for="(item,index) in twoList" :key="index" @click="navclick(index)">
            <a>{{item.class_name}}</a>
          </li>
        </ul>
      </div>

      <div class="right fr" :class="searchBarFixed1== true?'isFixed_r':''">
        <!-- 热门推荐 -->
        <div class="tj">
          <h2>热门推荐</h2>
          <ul>
            <li
              v-for="(item1,index1) in rmList"
              :key="index1"
              v-show="index1<8"
              @click="goto(item1.url,item1.type,item1.qr_code)"
              :title="item1.descript"
              @mouseover="showImg(-1,index1)"
              @mouseout="hideImg(item1.qr_code)"
            >
              <div class="left fl">
                <img
                  :src="'https://jiu.zhongyi9999.com'+item1.logo||item1.qr_code"
                  alt
                  style="width:100%;height:100%"
                />
              </div>
              <div class="right fl">
                <h3>{{item1.title}}</h3>
                <p>{{item1.descript}}</p>
              </div>
              <div class="qr_code" v-if="item1.type==2&&active==-1+'&'+index1">
                <i class="icon_top"></i>
                <img
                  :src="'https://jiu.zhongyi9999.com'+item1.qr_code"
                  alt
                  style="width:150px;height:150px"
                />
              </div>
              <!-- <img class="qr_code" :src="item1.qr_code" alt /> -->
              <!-- <div class="clear"></div> -->
            </li>
          </ul>
        </div>
        <!-- 栏目列表 -->
        <div class="tj" v-for="(item,index) in twoList" :key="index">
          <h2 :id="item.class_id">
            {{item.class_name}}
            <span @click="classfly(item.class_id,item.class_name)">更多></span>
          </h2>
          <ul>
            <li
              v-for="(item1,index1) in item.data"
              :key="index1"
              v-show="index1<8"
              @click="goto(item1.url,item1.type,item1.qr_code)"
              :title="item1.descript"
              @mouseover="showImg(index,index1)"
              @mouseout="hideImg(item1.qr_code)"
            >
              <div class="left fl">
                <img :src="item1.logo||item1.qr_code" alt style="width:100%;height:100%" />
              </div>
              <div class="right fl">
                <h3>{{item1.title}}</h3>
                <p>{{item1.descript}}</p>
              </div>
              <div class="qr_code" v-if="item1.type==2&&active==index+'&'+index1">
                <i class="icon_top"></i>
                <img :src="item1.qr_code" alt style="width:150px;height:150px" />
              </div>
            </li>
          </ul>
        </div>
      </div>
    </div>
    <!-- <div class="shade"></div> -->
  </div>
</template>
<script>
import eventVue from "../script/eventVue";
import { setTimeout } from "timers";

export default {
  data() {
    return {
      searchBarFixed: "",
      searchBarFixed1: false,
      scrollTop_z: "",
      twoList: [],
      active: "",
      rmList: [],
      active_nav: ""
    };
  },
  created() {
    // 热门推荐位
    this.$http
      .get("https://" + this.GLOBAL.serverSrc + "/api/getRecommand", {
        params: {}
      })
      .then(res => {
        console.log(234324);
        console.log(res.data.data);
        this.rmList = res.data.data;
      });
    // 默认显示股票的数据
    this.$http
      .get("https://" + this.GLOBAL.serverSrc + "/api/findBySite", {
        params: {
          stid: sessionStorage.stid || 1
        }
      })
      .then(res => {
        console.log(res.data.data[0].child);
        this.twoList = res.data.data[0].child;
        setTimeout(() => {
          $(".P_left ul li")
            .eq(0)
            .addClass("active");
        }, 200);
      });
    // 点击菜单导航获取到的数据传给mine组件
    eventVue.$on("data", msg => {
      console.log(msg);
      this.twoList = msg;
    });
    // 左侧菜单楼层效果
    var that = this;
    $(window).scroll(function() {
      var winH = $(window).height(); //窗口高度
      var iTop = $(window).scrollTop(); //鼠标滚动的距离
      $(".tj").each(function() {
        if (winH + iTop - $(this).offset().top > winH / 2 + 600) {
          $(".P_left ul li").removeClass("active");
          // console.log($(this).index());
          $(".P_left ul li")
            .eq($(this).index() + 1)
            .addClass("active");
        }
      });
      console.log($(window).scrollTop());
      if ($(window).scrollTop() < 480) {
        $(".P_left ul li").removeClass("active");
        $(".navclick_rm").addClass("active");
      }
    });
    //
  },
  mounted() {
    window.addEventListener("scroll", this.handleScroll);
    window.addEventListener("scroll", this.handleScroll1);
  },
  destroyed() {
    window.removeEventListener("scroll", this.handleScroll);
    window.removeEventListener("scroll", this.handleScroll1);
  },
  methods: {
    showImg(index, index1) {
      this.active = index + "&" + index1;
    },
    hideImg() {
      this.active = -1;
    },
    // 侦听滚轮距离顶部的距离
    handleScroll() {
      this.$nextTick(() => {
        let scrollTop =
          document.documentElement.scrollTop || document.body.scrollTop;
        let offsetTop = document.querySelector(".m_top").offsetTop;
        this.scrollTop_z = scrollTop;
        // console.log(this.scrollTop_z);
        if (scrollTop > 166) {
          this.searchBarFixed1 = true;
        } else {
          this.searchBarFixed1 = false;
        }
        if (scrollTop > offsetTop) {
          this.searchBarFixed = true;
        } else {
          this.searchBarFixed = false;
        }
      });
    },
    goto(url, type, qr_code) {
      if (type == 1) {
        window.open(url, "_blank"); // 新窗口打开外链接
      } else {
        const { href } = this.$router.resolve({
          path: "/qr_code",
          query: {
            url: qr_code
          }
        });
        // window.open(href, "_blank");
      }
    },
    classfly(classid, class_name) {
      this.$router.push({
        name: "more",
        params: { id: classid, name: class_name }
      });
      // window.location.reload();
    },
    // 点击二级导航楼层效果
    navclick(index) {
      console.log(index);
      var t = $(".tj")
        .eq(index + 1)
        .offset().top;
      $("body,html").animate({ scrollTop: t }, 500);
      // $(this)
      //   .addClass("active")
      //   .siblings()
      //   .removeClass("active");
    },
    // 点击热门
    navclick_rm(index) {
      console.log(index);
      var t = $(".tj")
        .eq(index + 1)
        .offset().top;
      console.log(t);
      $("body,html").animate({ scrollTop: t }, 500);
    }
  }
};
</script>

<style scoped>
@media screen and (min-width: 1024px) {
  .box {
    width: 100%;
    background-color: #f1f4f9;
    padding-bottom: 20px;
    position: relative;
    min-height: 650px;
  }
  .w1398 {
    display: flex;
  }
  .shade {
    width: 100%;
    height: 1000px;
    background-color: rgba(0, 0, 0, 0.5);
    position: fixed;
    left: 0;
    top: 0;
  }
  .qr_code {
    padding: 10px;
    border: 1px solid #bc8339;
    box-shadow: 1px 0px 3px #bc8339;
    position: absolute;
    top: 78px;
    left: 0;
    width: 150px;
    height: 150px;
    background: #fff;
    z-index: 1000;
  }
  .icon_top {
    background: url(../assets/image/top.png) no-repeat;
    width: 20px;
    height: 20px;
    display: inline-block;
    position: absolute;
    background-size: 100%;
    top: -13px;
    left: 23px;
  }
  .m_top {
    display: none;
  }
  .w1398 > .left {
    width: 200px;
    text-align: center;
    margin-top: 50px;
    position: absolute;
  }
  .w1398 > .right {
    margin-left: 200px;
    width: 100%;
  }
  .left ul li {
    line-height: 50px;
    cursor: pointer;
  }
  .active {
    background: url(../assets/image/icon_50.png) no-repeat 30px center;
  }
  .active a {
    color: #bc8339;
  }
  .left ul li:hover {
    color: #bc8339;
    /* background: url(../assets/image/icon_50.png) no-repeat 30px center; */
  }
  .left ul li:hover a {
    color: #bc8339;
  }
  .tj {
    width: 105%;
    /* height: 265px; */
    background: rgba(255, 255, 255, 1);
    border-radius: 6px;
  }
  .tj h2 {
    font-size: 20px;
    color: rgba(77, 77, 77, 1);
    line-height: 58px;
    padding-left: 20px;
    margin-top: 30px;
    border-bottom: 1px solid rgba(230, 230, 230, 1);
  }
  .tj h2 span {
    float: right;
    font-size: 16px;
    font-family: MicrosoftYaHei;
    font-weight: 400;
    color: rgba(128, 128, 128, 1);
    line-height: 58px;
    margin-right: 22px;
    cursor: pointer;
  }
  .tj ul {
    /* overflow: hidden; */
    display: flex;
    flex-wrap: wrap;
  }
  .tj ul li {
    position: relative;
  }
  .tj ul li .left {
    width: 45px;
    height: 45px;
    /* background: rgba(214, 172, 119, 1); */
    border-radius: 6px;
  }
  .tj ul li .right {
    margin-left: 6%;
  }
  .tj ul li .right h3 {
    font-size: 16px;
    color: rgba(77, 77, 77, 1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 200px;
  }
  .tj ul li .right p {
    font-size: 14px;
    font-family: MicrosoftYaHei;
    font-weight: 400;
    color: rgba(102, 102, 102, 1);
    line-height: 24px;
    margin-top: 5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 210px;
  }
  .w1398 {
    width: 1398px;
    margin: auto;
  }
  .tj ul {
    padding: 22px;
    min-height: 156px;
  }
  .tj ul li {
    width: 25%;
    padding: 14px 1%;
    box-sizing: border-box;
    min-width: 25%;
    cursor: pointer;
    /* height: 50%; */
  }
  .w1398 .isFixed {
    position: fixed;
    top: 0;
    /* left: 13.25%; */
    z-index: 999;
    /* margin-left: 13.25%; */
  }
  .isFixed_r {
    /* margin-left: 200px; */
  }
}

@media screen and (min-width: 320px) and (max-width: 1024px) {
  html {
    font-size: 62.5%;
    font-size: calc(100vw / 7.5);
    font-size: -webket-calc(100vw/7.5);
  }
  .w1398 > .left {
    display: none;
  }

  .box {
    width: 100%;
    /* height: 1237px; */
    background-color: #f1f4f9;
    font-size: 0.16rem;
    padding-bottom: 0.66rem;
    min-height: 10.5rem;
  }
  .w1398 {
    display: flex;
  }
  .m_top {
    /* display: inline;
    white-space: nowrap; */
  }
  .isFixed {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    z-index: 999;
  }

  .m_top ul {
    overflow: hidden;
    list-style-type: none;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-flex-wrap: nowrap;
    -ms-flex-wrap: nowrap;
    flex-wrap: nowrap;
    -webkit-box-pack: justify;
    -webkit-justify-content: space-between;
    -ms-flex-pack: justify;
    justify-content: space-between;
    background: #fff;
    padding: 0;
    overflow: auto;
    color: #000;
    height: 0.66rem;
    line-height: 0.66rem;
  }
  .m_top ul li {
    /* width: 1rem; */
    text-align: center;
    -webkit-box-flex: 1;
    -webkit-flex: 1 0 auto;
    -ms-flex: 1 0 auto;
    flex: 1 0 auto;
    padding: 0 5px;
    font-size: 0.22rem;
  }
  .m_top ul li:hover {
    color: red;
  }
  .tj {
    width: 7.1rem;
    /* height: 5.23rem; */
    margin: 0 0.2rem;
    background: rgba(255, 255, 255, 1);
    border-radius: 6px;
    margin-top: 0.2rem;
  }
  .tj h2 {
    font-size: 0.2rem;
    color: rgba(77, 77, 77, 1);
    line-height: 0.6rem;
    padding-left: 0.2rem;
    /* margin-top: 30px; */
    border-bottom: 1px solid rgba(230, 230, 230, 1);
    font-size: 0.2rem;
  }
  .tj h2 span {
    float: right;
    font-size: 0.16rem;
    font-family: MicrosoftYaHei;
    font-weight: 400;
    color: rgba(128, 128, 128, 1);
    line-height: 0.58rem;
    margin-right: 0.22rem;
    cursor: pointer;
  }
  .tj ul {
    overflow: hidden;
    display: flex;
    flex-wrap: wrap;
    padding: 15px;
  }
  .tj ul li {
    width: 48%;
    margin: 1%;
    box-sizing: border-box;
    padding: 12px 0px;
  }
  .tj ul li .left {
    width: 0.45rem;
    height: 0.45rem;
    background: rgba(76, 180, 247, 1);
    border-radius: 0.06rem;
    margin-top: 0.08rem;
  }
  .tj ul li .right {
    margin-left: 3%;
    width: 2.5rem;
  }
  .tj ul li .right h3 {
    font-size: 0.2rem;
    line-height: 0.32rem;
  }
  .tj ul li .right p {
    font-size: 0.17rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>

